<template>
  <div>
    <SelectData :tableData="tableData" :pagination="pagination" :chooseFeild="chooseFeild" :multiple="false" @confirm="confirm" :getList="getLeftData" @search="search" id="orgId" :select="orgIds"/>
  </div>
</template>

<script>
import authRequest from '@/api/identity/auth.js'
import { mapState, mapMutations } from 'vuex'
import SelectData from '@/components/common/newSelectData.vue'
export default {
    data () {
        return {
            tableData: [],
            pagination: {
                'limit': 10,
                'page': 1,
                'total': 0,
            },
            chooseFeild: [
                { label: '机构编码', prop: 'shortCode' },
                { label: '机构名称', prop: 'orgName' }
            ],
            orgIds: []
        }
    },
    components: {
        SelectData
    },
    computed: {
        ...mapState(['userInfo'])
    },
    mounted () {
        this.getLeftData()
        this.orgIds = [ localStorage.getItem('orgId') ]
    },
    methods: {
        ...mapMutations(['setDialogData']),
        getLeftData () {
            authRequest.hrOrgGetOrgByUserId({
                userId: this.userInfo.userId
            }).then(res => {
                if(this.pagination.key || this.pagination.key === 0 || this.pagination.key === '0') {
                    this.tableData = res.filter(x=>x.orgName.includes(this.pagination.key))
                }else{
                    this.tableData = res
                }
                this.pagination.limit = res.length
            }).catch(()=>{
            })
        },
        confirm (res) {
            this.orgIds = res.map(x=>x.orgId)
            this.setDialogData(res)
        },
        search (e) {
            this.pagination = e
            this.getLeftData()
        },
    },
}
</script>

<style>

</style>